<%--@elvariable id="typeName" type="java.lang"--%>
<%--
  Created by IntelliJ IDEA.
  User: gaoyang
  Date: 14-4-29
  Time: 下午4:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="../../includes/common.jsp" %>
    <title>新增分类值</title>
<body>
<div id="mainContent">
    <form class="form-horizontal" action="">
        <fieldset>
            <!-- Form Name -->
            <legend></legend>

            <div class="control-group">
                <label class="control-label" for="typeValue">分类值</label>

                <div class="controls">
                    <input id="typeValue" name="typeValue" type="text">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"></label>

                <div class="controls">
                    <input type="button" class="btn btn-primary" onclick="save()" id="saves" value="保存"/>
                    <input type="button" class="btn btn-primary" onclick="quit()" value="取消"/>
                </div>
            </div>
        </fieldset>
    </form>
</div>
</body>
</html>
<script type="text/javascript">
    var rules = {
        objInfo: {
            typeCode: {
                checkEmpty: ["typeValue", "分类值"],
                 ajax: [basePath + "classify/checkRepeatTypeValue", {typeName: "${typeName}"}, {typeCode: "$('#typeValue').val().trim()"},
                    backFunc, "text", "POST"]
            }
        }
    };

    function backFunc(data, returnObj) {
        returnObj.obj = $('#typeValue');
        returnObj.errMsg = "分类码已存在！";
        if (data == "true") {
            returnObj.bool = true;
        }
        if (data == "false") {
            returnObj.bool = false;
        }
        return returnObj;
    }

    function save() {
        if (!JC.validate(rules)) return;
        $("#saves").button('loading');
        $.ajax({
            url: basePath + "classify/addTypeValue",
            data: {
                typeName: "${typeName}",
                typeValue: $("#typeValue").val()
            },
            dataType: "json",
            type: "POST",
            success: function () {
                $.messager.alert("提示", "新增成功！", "", function () {
                    parent.$("#dataEdit").dialog('close');
                    parent.query();
                });
            },
            error: doError
        })
    }

    function quit() {
        parent.$("#dataEdit").dialog('close');
    }
</script>
